Ext.define('NIM.view.Report.SiteCostList', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.SiteCostList',
    id: 'SiteCostListId',
    border: false,
    title : 'Site Cost',
    layout : 'fit',
    closable: true,
    width: 1 * screen.width,
    height: 590,
    items: 
    [ 
	    {
            xtype: 'gridpanel',
            plugins: [Ext.create('Ext.grid.plugin.RowEditing', {
                listeners: {
                    cancelEdit: function(rowEditing, context) {
                        // Canceling editing of a locally added, unsaved record: remove it
                        if (context.record.phantom) {
                            store.remove(context.record);
                        }
                    }
                }
            })],
            region: 'center',
            titleAlign: 'center',
            title   : 'Site List',
	        margin: '5 5 5 5',
	        scroll: 'both',
	        columnLines: true,
            store: 'Report.SiteCostStore',
            columns: [
	            { dataIndex: 'SITE_ID', text: 'Site ID', align: 'left',style: 'text-align: center;', renderer: function(v, meta, rec) {
	                return rec.phantom ? '' : v;
	            } },
	            { dataIndex: 'SITE_NAME', text: 'Site Name', align: 'left', style: 'text-align: center;' },
	            { dataIndex: 'REVENUE', text: 'Revenue Mar2014', align: 'center', field: {xtype: 'textfield' } },
	            { dataIndex: '',text: 'OAM', align: 'center', width : 800, 
	            columns :[{text :'NSR', dataIndex :'NSR', align: 'center',},
	                      {text :'PS', width:300, dataIndex :"", align: 'left',
	                       columns:[{text:'PLN', 	   dataIndex: 'PS_PLN', align: 'left',style: 'text-align: center;'},
	            	  	          {text:'NON-PLN', dataIndex :'PS_NON_PLN', align: 'center'},
	            	  	          {text:'TOTAL PS',dataIndex :'PS_TOTAL', align: 'center'},
	            	  	         ]},
            	  	      {text :'TRANSMISI', dataIndex :"", width:500, align: 'center',
            	  	       columns:[{text:'IDR Site', 	dataIndex :"", align: 'center'},
	            	  	          {text:'IDR Core', 	dataIndex :"", align: 'center'},
	            	  	          {text:'Non-IDR',  	dataIndex :"", align: 'center'},
	            	  	          {text:'TOTAL Trans',	dataIndex :'TRANS_TOTAL', align: 'center'}
	            	  	         ]},
        	  	         {text :'FREKUENSI', dataIndex :'FREKUENSI', align: 'center'},
        	  	         {text :'RM', 		 dataIndex :'RM', align: 'center'},
        	  	         {text :'TOTAL OAM', dataIndex :"", align: 'center'}
        	  	        ]},      
	            { dataIndex: '', text: 'REVENUE OAM', align: 'center' },
	            { dataIndex: '', text: 'RATIO OAM per </br> REVENUE', align: 'center'},
	            { dataIndex: '', text: 'NSR', align: 'center',width :400,
            	  columns :[{text :'TOWER', dataIndex :"", width :200, align: 'center',
	              columns:[{text:'TP Name',	  dataIndex :"", align: 'center'},
	            	  	         {text:'Beli / Sewa', dataIndex :"", align: 'center'}
	            	  	        ]},
            	  	      {text :'LAND', dataIndex :"", width :200, align: 'center',
            	  	       columns:[{text:'Name', 		dataIndex :"", align: 'center'},
	            	  	          {text:'Beli / Sewa',  dataIndex :"", align: 'center'}
	            	  	   		 ]}
            	  	     ]},
                { dataIndex: '', text: 'PS', align: 'center',width :200,
                  columns:[{text:'TIPE PS', dataIndex :"", align: 'center'},
	                     {text:'PLN ID',  dataIndex :"", align: 'center'}
	              		]}],
		    
      		listeners: {
		    	afterrender: function() {
                    Ext.getStore('Report.SiteCostStore').load();    
                },
			    /*itemdblclick: function(grid, record) {
			    	    site_id = record.raw.site_id;
		    	 		OpenTab('widget.addnewsitemaster','addnewsitemaster');
                       
			    	 }*/
	        	},
            dockedItems: 
            [
             	{
	                xtype: 'pagingtoolbar',
	                dock: 'bottom',
	                store: 'AssetDataMaster.SiteList',
	                displayInfo: true
	            }, 
	            {
	                xtype: 'toolbar',
	                dock: 'top',
	                height:65,
	                padding:'5 0 0 0',
	            layout : {
					type : 'table',
					columns : 13

				},

	                items: 
                	[
						{
							xtype: 'combobox',
							id: 'SiteCostPeriod1',
							displayField: 'period',
							valueField: 'period',
							allowBlank : false,
							margin: '0 5 0 5',
							labelWidth: 35,
							width: 110,
							store: 'AssetDataMaster.Area',
							fieldLabel: 'Period',
						},
						{	xtype: 'tbseparator' },
	                    
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataArea1',
		                	displayField: 'area_description',
		                	valueField: 'area_code',
		                	emptyText       : 'All Area',
		                	allowBlank : true,
		                	margin: '0 5 0 5',
		                	labelWidth: 35,
		                	width: 155,
		                	store: 'AssetDataMaster.Area',
		                	fieldLabel: 'Area',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                			Ext.getCmp('AssetDataRegional').setValue('');
		                        	Ext.getStore('AssetDataMaster.Regional').removeAll();
		                            Ext.getStore('AssetDataMaster.Regional').getProxy().url = './Services/DataMaster/Region/List?area=' + newValue;
		                            Ext.getStore('AssetDataMaster.Regional').load();
									Ext.getCmp('AssetDataRegional').setValue('');
		                        }
		                    }
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataRegional1',
		                	displayField: 'region_description',
		                	emptyText       : 'All Region',
		                	margin: '0 5 0 5',
		                	labelWidth: 50,
		                	width: 210,
		                	valueField: 'region_code',
		                	store: 'AssetDataMaster.Regional',
		                	fieldLabel: 'Regional',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                            Ext.getStore('AssetDataMaster.Provinsi').load();
		                        }
		                    }
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataProvinsi1',
		                	displayField: 'nama_prov',
		                	emptyText       : 'All Propinsi',
						 	margin: '0 5 0 5',
						 	labelWidth: 45,
						 	width: 200,
						 	store: 'AssetDataMaster.Provinsi',
		                	valueField: 'id_prov',
						 	fieldLabel: 'Provinsi',
		                    listeners: {
		                    	select: function(obj, newValue, oldValue, eOpts) {
		                    	    var id_prof = Ext.getCmp("AssetDataProvinsi").getValue();
			                    	Ext.getStore('AssetDataMaster.Kabupaten').removeAll();
		                            Ext.getStore('AssetDataMaster.Kabupaten').getProxy().url = './Services/DataMaster/Kabupaten/List?propinsi=' + id_prof;
		                            Ext.getStore('AssetDataMaster.Kabupaten').load();

		                    	}
		                    }
		                },
		                { xtype: 'tbseparator' },
		                {
		                	xtype: 'combobox',
		                	id: 'AssetDataKabupaten1',
		                	displayField: 'nama_kabkot',
		                	emptyText       : 'All Kabupaten',
		                	margin: '0 5 0 5',
		                	labelWidth: 55,
		                	width: 220,
		                	store: 'AssetDataMaster.Kabupaten',
		                	fieldLabel: 'Kabupaten',
		                	valueField: 'id_kabkot'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                    xtype: 'textfield',
		                    id: 'AssetDataKeyword1',
		                    margin: '0 5 0 5',
		                    labelWidth: 50,
		                    fieldLabel: 'Keyword'
		                },
		                
		                {	xtype: 'tbseparator' },
		                {
		                    xtype: 'button',
		                    id: 'AssetDataMasterSearch1',
		                    text: 'Search',
				    		handler: function() {
		                	   //OpenTab('widget.addnewsitemaster','addnewsitemaster');
		                		var keyword = Ext.getCmp('AssetDataKeyword').getValue();
		                		var area = Ext.getCmp('AssetDataArea').getValue();
		                		var region = Ext.getCmp('AssetDataRegional').getValue();
		                		var provinsi = Ext.getCmp('AssetDataProvinsi').getValue();
		                		var kabupaten = Ext.getCmp('AssetDataKabupaten').getValue();	
			            		Ext.getStore('AssetDataMaster.SiteList').removeAll();
			            		Ext.getStore('AssetDataMaster.SiteList').getProxy().url = "./Services/Asset/Site/List?keyword=" + keyword + '&area=' + area + 
			            				"&region=" + region + "&prop=" + provinsi + "&kabkot=" + kabupaten; 
			            		Ext.getStore('AssetDataMaster.SiteList').load();
				    		}
		                },
		                {
		                	xtype : 'button',
		                	text  : 'Add Site From NIM',
		                	margin: '5 0 0 5',
			                handler : function() {
			                	AddDataFromNIM();
		
		                       }
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype : 'button',
		                	text  : 'Add Site From File',
		                	margin: '5 0 0 0'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype : 'button',
		                	text  : 'Generate NSR Cost',
		                	margin: '5 0 0 0'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype : 'button',
		                	text  : 'Generate Power Supply Cost',
		                	margin: '5 0 0 0'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype : 'button',
		                	text  : 'Add Transmisi',
		                	margin: '5 0 0 0'
		                },
		                {	xtype: 'tbseparator' },
		                {
		                	xtype : 'button',
		                	text  : 'Export To Xls',
		                	margin: '5 0 0 0'
		                }
		                
		                
		                
		                
	                ]
	            }
            ]
        }
    ]
});

